import { QueryClient, useMutation, useQuery } from "@tanstack/react-query";
import { DisciplineService } from "@/shared/api/api.discipline";

export function useGetAllDisciplines() {
    const queryClient = new QueryClient    
    const { isLoading, error, data, refetch,isSuccess } =
        useQuery(
            {
                queryKey: ['query-getAllDisciplines'],
                queryFn: DisciplineService.getAll,
            }, queryClient
        )

    const errorMessage = error ? "Load disciplines failed" : undefined;

    return {
        disciplines: data,
        errorMessage,
        refetch,
        isSuccess,
        isLoading
    };
}